using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using LeadTracker.EFCodeFirst.Entities;

namespace LeadTracker.EFCodeFirst.Mapping
{
	public class LeadCommentMap : EntityTypeConfiguration<LeadComment>
	{
		public LeadCommentMap()
		{
			// Primary Key
			this.HasKey(t => t.LeadCommentKey);

			// Properties
			this.Property(t => t.Comment)
				.IsRequired();
				
			// Table & Column Mappings
			this.ToTable("LeadComment");
			this.Property(t => t.LeadCommentKey).HasColumnName("LeadCommentKey");
			this.Property(t => t.LeadKey).HasColumnName("LeadKey");
			this.Property(t => t.Comment).HasColumnName("Comment");
			this.Property(t => t.CreatedByKey).HasColumnName("CreatedByKey");
			this.Property(t => t.CreatedDate).HasColumnName("CreatedDate");

			// Relationships
			this.HasRequired(t => t.Editor)
				.WithMany(t => t.LeadComments)
				.HasForeignKey(d => d.CreatedByKey);
				
			this.HasRequired(t => t.Lead)
				.WithMany(t => t.LeadComments)
				.HasForeignKey(d => d.LeadKey);
				
		}
	}
}

